From 79238b0d8f8683b57ba85e27b3cdf0949011a8d1 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 10 Apr 2019 19:42:09 +0200 Subject: [PATCH] cssparser: Add error functions that take locations ... and use them to report better error locations for the warning when blocks aren't terminated properly. --- gtk/css/gtkcssparser.c | 52 +++++++++++++++++++++++++++++++++-- gtk/css/gtkcssparserprivate.h | 13 +++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/gtk/css/gtkcssparser.c b/gtk/css/gtkcssparser.c index b3347ee067..e812df259b 100644 --- a/gtk/css/gtkcssparser.c +++ b/gtk/css/gtkcssparser.c @@ -415,13 +415,21 @@ gtk_css_parser_end_block (GtkCssParser *self) if (gtk_css_token_is (&self->token, GTK_CSS_TOKEN_EOF)) { - gtk_css_parser_warn_syntax (self, "Unterminated block at end of document"); + gtk_css_parser_warn (self, + GTK_CSS_PARSER_WARNING_SYNTAX, + gtk_css_parser_get_block_location (self), + gtk_css_parser_get_start_location (self), + "Unterminated block at end of document"); g_array_set_size (self->blocks, self->blocks->len - 1); } else if (gtk_css_token_is (&self->token, block->inherited_end_token)) { g_assert (block->end_token == GTK_CSS_TOKEN_SEMICOLON); - gtk_css_parser_warn_syntax (self, "Expected ';' at end of block"); + gtk_css_parser_warn (self, + GTK_CSS_PARSER_WARNING_SYNTAX, + gtk_css_parser_get_block_location (self), + gtk_css_parser_get_start_location (self), + "Expected ';' at end of block"); g_array_set_size (self->blocks, self->blocks->len - 1); } else @@ -498,6 +506,26 @@ gtk_css_parser_emit_error (GtkCssParser *self, self->error_func (self, start, end, error, self->user_data); } +void +gtk_css_parser_error (GtkCssParser *self, + GtkCssParserError code, + const GtkCssLocation *start, + const GtkCssLocation *end, + const char *format, + ...) +{ + va_list args; + GError *error; + + va_start (args, format); + error = g_error_new_valist (GTK_CSS_PARSER_ERROR, + code, + format, args); + gtk_css_parser_emit_error (self, start, end, error); + g_error_free (error); + va_end (args); +} + void gtk_css_parser_error_syntax (GtkCssParser *self, const char *format, @@ -558,6 +586,26 @@ gtk_css_parser_error_import (GtkCssParser *self, va_end (args); } +void +gtk_css_parser_warn (GtkCssParser *self, + GtkCssParserWarning code, + const GtkCssLocation *start, + const GtkCssLocation *end, + const char *format, + ...) +{ + va_list args; + GError *error; + + va_start (args, format); + error = g_error_new_valist (GTK_CSS_PARSER_WARNING, + code, + format, args); + gtk_css_parser_emit_error (self, start, end, error); + g_error_free (error); + va_end (args); +} + void gtk_css_parser_warn_syntax (GtkCssParser *self, const char *format, diff --git a/gtk/css/gtkcssparserprivate.h b/gtk/css/gtkcssparserprivate.h index 2942bb86f1..31b44cbce6 100644 --- a/gtk/css/gtkcssparserprivate.h +++ b/gtk/css/gtkcssparserprivate.h @@ -21,6 +21,7 @@ #ifndef __GTK_CSS_PARSER_H__ #define __GTK_CSS_PARSER_H__ +#include "gtkcssenums.h" #include "gtkcsstokenizerprivate.h" #include @@ -87,6 +88,12 @@ void gtk_css_parser_emit_error (GtkCssParser const GtkCssLocation *start, const GtkCssLocation *end, const GError *error); +void gtk_css_parser_error (GtkCssParser *self, + GtkCssParserError code, + const GtkCssLocation *start, + const GtkCssLocation *end, + const char *format, + ...) G_GNUC_PRINTF(5, 6); void gtk_css_parser_error_syntax (GtkCssParser *self, const char *format, ...) G_GNUC_PRINTF(2, 3); @@ -96,6 +103,12 @@ void gtk_css_parser_error_value (GtkCssParser void gtk_css_parser_error_import (GtkCssParser *self, const char *format, ...) G_GNUC_PRINTF(2, 3); +void gtk_css_parser_warn (GtkCssParser *self, + GtkCssParserWarning code, + const GtkCssLocation *start, + const GtkCssLocation *end, + const char *format, + ...) G_GNUC_PRINTF(5, 6); void gtk_css_parser_warn_syntax (GtkCssParser *self, const char *format, ...) G_GNUC_PRINTF(2, 3); -- 2.30.2